<template>
  <div>
    <input placeholder="输入关键字搜索" v-model="uname" />
    <table class="my-table">
      <thead>
        <tr>
          <th>就诊日期</th>
          <th>医生姓名</th>
          <th>诊断结果</th>
          <th>处方信息</th>
          <th>操作</th>
        </tr>
      </thead>
      <tbody>
        <my-person
          v-for="item in list"
          :key="item.name"
          :time="item.time"
          :uname="item.uname"
          :result="item.result"
          :message="item.message"
        ></my-person>
      </tbody>
    </table>
  </div>
</template>

<script>
import MyPerson from './components/MyPerson.vue'
export default {
  components: { MyPerson },
  data() {
    return {
      list: [
        {
          time: '2020 - 12 - 12',
          uname: '张三',
          result: '健康',
          message: '无',
        },
        {
          time: '2020 - 12 - 12',
          uname: '李四',
          result: '头疼',
          message: '止痛药',
        },
        {
          time: '2020 - 12 - 12',
          uname: '王五',
          result: '骨折',
          message: '住院',
        },
      ],
      lists: false,
      uname: '',
    }
  },
  methods :{
  
  },
  watch: {
    uname() {
      // this.list.find((item) => item.uname === this.uname
      if (this.uname) {
     if(this.list.find((item) => item.uname === this.uname)) {
      this.lists = JSON.parse(JSON.stringify(this.list))
     } 
        this.list  = this.list.filter((item) => {
          return item.uname === this.uname
        })
      } else {
        if (this.lists) {
          this.list = this.lists
        }
      }
    },
  },

}
</script>
<style>
.my-table {
  border-collapse: collapse;
  width: 100%;
}

.my-table td,
.my-table th {
  border: 1px solid #ddd;
  padding: 8px;
  text-align: left;
}

.my-table th {
  background-color: #f2f2f2;
}
</style>
